﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Marmat.Foundation;

namespace Marmat.Template.WinForm
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Alert : System.Windows.Forms.Form, Marmat.Foundation.IAlert
    {
        int top = 40;
        Color foreColor;
        Color backColor;

        public Alert()
        {
            InitializeComponent();
            this.Location = new Point((Screen.PrimaryScreen.Bounds.Width - this.Width) / 2, 68);
        }

        private void Alert_Load(object sender, EventArgs e)
        {

        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
            using (Pen pen = new Pen(Color.FromArgb(80, foreColor)))
            {
                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                e.Graphics.DrawRectangle(pen, rect);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.timer1.Tag?.ToString() == "1")
                this.Close();
            else
            {
                top -= 1;
                this.Top = 28 + top;
            }
            if (top <= 0)
            {
                this.timer1.Interval = 1000;
                this.timer1.Tag = "1";
            }
        }

        /// <summary>
        /// 显示消息提醒
        /// </summary>
        /// <param name="title">提醒的内容。</param>
        /// <param name="type">提醒的类型。</param>
        public void Show(string title, AlertTypeEeum type)
        {
            switch (type)
            {
                case AlertTypeEeum.Success:
                    foreColor = Color.FromArgb(103, 194, 58);
                    backColor = Color.FromArgb(240, 244, 235);
                    break;
                case AlertTypeEeum.Info:
                    foreColor = Color.FromArgb(144, 147, 153);
                    backColor = Color.FromArgb(244, 244, 245);
                    break;
                case AlertTypeEeum.Warning:
                    foreColor = Color.FromArgb(230, 162, 60);
                    backColor = Color.FromArgb(253, 246, 236);
                    break;
                case AlertTypeEeum.Error:
                    foreColor = Color.FromArgb(245, 108, 106);
                    backColor = Color.FromArgb(254, 240, 240);
                    break;
            }
            this.label1.Text = title;
            this.label1.ForeColor = foreColor;
            this.label1.BackColor = backColor;
            this.BackColor = backColor;
            this.Show();
        }

        /// <summary>
        /// 获取一个值，该值指示显示窗口时是否激活它。
        /// </summary>
        protected override bool ShowWithoutActivation => true;
    }
}
